package com.md.facade;

import com.md.api.OpenSystemApi;
import com.md.application.service.OpenSystemApplicationService;
import com.md.config.Logs;
import com.md.model.system.CommonResult;
import com.md.request.ApiRequest;
import com.md.request.AppInfoRequest;
import com.md.request.BatchIdRequest;
import com.md.request.QueryAppInfoRequest;
import com.md.request.QueryModuleRequest;
import com.md.response.ApiResponse;
import com.md.response.AppInfoResponse;
import com.md.response.ModuleResponse;
import com.md.value.ApiTypeEnum;
import com.md.value.AppTypeEnum;
import com.md.value.ModuleTypeEnum;
import com.md.value.enums.OperationEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 刘骄阳
 * 2024-07-14 22:16
 */
@RestController
@RequiredArgsConstructor
public class OpenSystemController implements OpenSystemApi {
  private final OpenSystemApplicationService openApplicationService;

  @Override
  @Logs(title = "批量查询应用信息", operation = OperationEnum.SELECT)
  public CommonResult<AppInfoResponse> openQuery(final QueryAppInfoRequest request) {
    request.setAppType(AppTypeEnum.PUBLIC);
    return openApplicationService.openQuery(request);
  }

  @Override
  @Logs(title = "批量查询应用信息", operation = OperationEnum.SELECT)
  public CommonResult<List<AppInfoResponse>> openQueryList(final QueryAppInfoRequest request) {
    request.setAppType(AppTypeEnum.PUBLIC);
    return openApplicationService.openQueryList(request);
  }

  @Override
  @Logs(title = "批量查询应用信息根据ids", operation = OperationEnum.SELECT)
  public CommonResult<List<AppInfoResponse>> openQueryIdsList(final BatchIdRequest request) {
    return openApplicationService.openQueryIdsList(request);
  }

  @Override
  @Logs(title = "新增api", operation = OperationEnum.INSERT)
  public CommonResult<Void> openCreateApi(final ApiRequest request) {
    return openApplicationService.openCreateApi(request);
  }

  @Override
  @Logs(title = "新增appInfo", operation = OperationEnum.INSERT)
  public CommonResult<Void> openCreateAppInfo(final AppInfoRequest request) {
    return null;
  }

  @Override
  @Logs(title = "批量查询模块信息", operation = OperationEnum.SELECT)
  public CommonResult<List<ModuleResponse>> openQueryList(final QueryModuleRequest request) {
    request.setModuleType(ModuleTypeEnum.PUBLIC);
    return openApplicationService.openQueryList(request);
  }

  @Override
  @Logs(title = "批量查询接口信息", operation = OperationEnum.SELECT)
  public CommonResult<List<ApiResponse>> openQueryList(final ApiRequest request) {
    request.setApiType(ApiTypeEnum.PUBLIC);
    return openApplicationService.openQueryList(request);
  }

  @Override
  @Logs(title = "查询接口信息", operation = OperationEnum.SELECT)
  public CommonResult<ApiResponse> openQuery(final ApiRequest request) {
    return openApplicationService.openQuery(request);
  }

  @Override
  @Logs(title = "查询接口信息", operation = OperationEnum.SELECT)
  public CommonResult<ApiResponse> openQueryByUrlMethod(final ApiRequest request) {
    return openApplicationService.openQueryByUrlMethod(request);
  }

  @Override
  @Logs(title = "查询接口信息-通过id列表", operation = OperationEnum.UPDATE)
  public CommonResult<List<ModuleResponse>> openQueryListByIdList(final QueryModuleRequest request) {
    request.setModuleType(ModuleTypeEnum.PUBLIC);
    return openApplicationService.openQueryListByIdList(request);
  }

  @Override
  @Logs(title = "根据moduleId批量查询应用信息", operation = OperationEnum.SELECT)
  public CommonResult<List<AppInfoResponse>> openQueryListByModuleId(final QueryAppInfoRequest request) {
    return openApplicationService.openQueryListByModuleId(request);
  }
}
